package com.jianyun.jyzs.utils;

import android.app.Activity;
import android.app.ProgressDialog;


import com.jianyun.jyzs.bean.SignResult;
import com.jianyun.jyzs.http.Api;
import com.jianyun.jyzs.http.CustomCallback;
import com.jianyun.jyzs.http.RetrofitHelper;

import java.util.HashMap;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by mlli on 2017/11/14.
 */

public class SignUtils {

    public interface SignResltListener{
        void signSuccess(SignResult response);
        void signFail(String response);
    }

    public static void signDao(final ProgressDialog dialog, final Activity context, HashMap<String, String> map, final SignResltListener listener){
        dialog.setMessage("开始签到");
        Api api = RetrofitHelper.builderErpRoot().create(Api.class);
        api.userSignDao(map)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new CustomCallback<SignResult>() {
                    @Override
                    protected void onResponse(SignResult response) {
                        dialog.setMessage("签到完成"+response.getMessage());
                        dialog.dismiss();
                        if (response.isResult()){
                            if (listener!=null)listener.signSuccess(response);
                        }else {
                            if (listener!=null)listener.signFail(response.getMessage());
                        }
                    }

                    @Override
                    protected void onException(String msg) {
                        dialog.dismiss();
                        if (listener!=null)listener.signFail(msg);
                    }
                });

    }
}
